import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/pages/student/evaluationOverviewChart.dart';
import 'package:ichinesereader/pages/student/evaluationRecords.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/charts/evaluationLinguisticSkillsTreeView.dart';
import 'package:ichinesereader/widgets/charts/evaluationLinguisticTreeMap.dart';
import 'package:ichinesereader/widgets/charts/evaluationProficiencySkillProgressTreeView.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerStudent.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/sidebars/studentSidebar.dart';
import '../../themes/appTheme.dart';

class EvaluationHomepageForStudent extends StatefulWidget {
  static const String routeName = '/student/evaluation';

  @override
  State<EvaluationHomepageForStudent> createState() =>
      _EvaluationHomepageForStudentState();
}

class _EvaluationHomepageForStudentState
    extends State<EvaluationHomepageForStudent> {
  final box = Hive.box('appconfig');

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build student evaluation home page');

    bool isStudent = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Student;
    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.studentPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    return DefaultTabController(
      length: 5,
      child: Scaffold(
        drawer: isSmallScreen ? StudentAppDrawer() : null,
        appBar: isSmallScreen ? CustomAppBar(title: 'Evaluation') : null,
        body: Container(
          decoration: _pageStyles.pageBoxDecoration(),
          child: Row(
            children: [
              Visibility(
                  visible: !isSmallScreen,
                  child: StudentSidebarX(
                      selectedIndex: _selectedSidebarItem,
                      isBigScreen: isBigScreen)),
              Expanded(
                child: Container(
                  margin: _pageStyles.mainContainerPageEdgeInsets(),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 9.0),
                        margin: EdgeInsets.only(bottom: 12.0),
                        decoration: BoxDecoration(
                          color: Get.isDarkMode
                              ? AppTheme.colors.darkTheme2
                              : Colors.black.withOpacity(0.1),
                          borderRadius: BorderRadius.circular(3.0),
                        ),
                        child: _pageStyles.buildTabBar([
                          'Overview',
                          'Records',
                          'Proficiency',
                          'Linguistics',
                          'Language Skills',
                        ]),
                      ),
                      Expanded(
                        flex: 9,
                        child: Container(
                          child: isStudent
                              ? TabBarView(
                                  children: [
                                    EvaluationOverviewChartStudentPage(),
                                    EvaluationRecordsForStudent(),
                                    EvaluationProficiencySkillsTreeview(),
                                    EvaluationLinguisticTreeMap(),
                                    EvaluationLinguisticSkillsTreeView(),
                                    //EvaluationLinguisticSkillsTreeGraph(),
                                  ],
                                )
                              : Text(''),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
